<?php
namespace app\admin\controller;

use think\Controller;
use think\Db;
use think\Request;
use think\Validate;
use think\Session;
use app\admin\model\User;

class Member extends Controller
{
    public function __construct(){
        $user = Session::has('user');
        if ($user) {
            $user = Session::get('user');
        }else{
            $this->success('未登录', 'login/login');
        }
        parent::__construct();
    }

    public function member_list()
    {
        $user = new User();
        $data = $user->get_Member();
        $this->assign([
            'data'  =>  $data
        ]);
        return $this->fetch();
    }

    public function member_add()
    {
        return $this->fetch();
    }

    public function member_show()
    {
        return $this->fetch();
    }

    public function member_rank()
    {
        $user = new User();
        $rank = $user->get_Rank();
        $this->assign([
            'data'  =>  $rank
        ]);
        return $this->fetch();
    }

    public function member_rank_add()
    {
        $user = new User();
        if (Request::instance()->isPost()) {
            $data = input('post.');
            $res = $user->get_RankAdd($data);
            if ($res) {
                $this->success('添加成功');
            }else{
                $this->error('添加失败');
            }
        }
        return $this->fetch();
    }

    public function member_rank_edit()
    {
        $user = new User();
        $id = input('param.id');
        $rank = $user->get_RankOne($id);
        if (Request::instance()->isPost()) {
            $data = input('post.');
            $res = $user->get_RankEdit($data,$id);
            if ($res) {
                $this->success('修改成功');
            }else{
                $this->error('修改失败');
            }
        }
        $this->assign([
            'rank'  =>  $rank
        ]);
        return $this->fetch();
    }

    public function member_rank_del()
    {
        $user = new User();
        $id = input('param.id');
        $res = $user->get_RankDel($id);
        if ($res) {
            return 200;
        }else{
            return 400;
        }
    }
    
    public function points_list()
    {
        $user = new User();
        $data = $user->get_PointsList();
        $this->assign([
            'data'  =>  $data
        ]);
        return $this->fetch();
    }

    public function member_log()
    {
        $user = new User();
        $data = $user->get_MemberLog();
        $this->assign([
            'data'  =>  $data
        ]);
        return $this->fetch();
    }
}
